#ifndef ZBNNMW_H
#define ZBNNMW_H

/************************************************
 *
 *作者：刘通
 *因为是QMainWindow类不适合使用作为子窗口
 *修改人：周翔 2012-12-07
 *
 *后续修改 zhou xiang
 ************************************************/


//#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItemGroup>
#include <QGraphicsItem>
#include <QPrinter>
#include <QPoint>
#include <QDataStream>
#include <QVector>

#include "graphicsview.h"
#include "itemtype.h"
#include "zigbeenode.h"
#include "edge.h"
#include <QTimer>
#include "StateWidgets.h"
#include "model/node.h"
class ZBNNMW : public QWidget//QMainWindow
{
    Q_OBJECT

public:
    explicit ZBNNMW(QWidget *parent = 0);
    ~ZBNNMW();
public:
    QPoint position();
    bool sceneHasItems();
    void createDockWidgets();
    void createSceneAndView();
    void RemoveEdges(QList<Edge*> m_edge);
    void viewShowGrid();
    void Bangding(QString adress1,QString adress2);
signals:
    void senMessage(ZigBeeNode*Nodeitem);
    void sig_tree_clear();
public slots:
    void slt_netTopologyBuild(const QString &value);
    void Domessage();
    void recveMessage(ZigBeeNode*Nodeitem);
    void AddNodeToMap(const Node &node);
    /**
     * @brief ChangNodeState
     * @param node
     * @note 这个点肯定在视图中
     */
    void ChangNodeState(const Node &node);

    void ChangNodeState(int type, const QString &addr, const QString &paddr, ushort _name, bool status);
    void UpdateMap();
    ZigBeeNode*FindParent(const Node &m_node);
    ZigBeeNode*FindParent(const QString &s);


    void slt_updataNodeValue(ushort name,int value);


private slots:
    void slt_max_show();//add by zhou xiang 2013-12-13 实现最大化显示
private:


    QGraphicsScene *scene;
    GraphicsView*view;
    QGraphicsItemGroup*backgroundGrid;
    QGraphicsTextItem *showInfoItem;//用来实时数据
    QPoint previouspoint;
    int addOffset;
    int pasteOffset;
    QList<ZigBeeNode*>nodelist;
    NodeStateWidget*nodewidget;
    QMenu *fileMenu;
    QAction *viewShowGridAction;
    ZigBeeNode*Nodeitem;
    QTimer*timer;

    QMap<QString,QString>Child_ParentMaps;
    QMap<Node*,ZigBeeNode*>DeadNodeMaps;
    /**
     * @brief deleteItemsByParentAdd 删除所有以padd为父节点的节点,这边对链表的递归访问，问题很大啊
     * @param padd
     */
    void deleteItemsByParentAdd(const QString &padd);

    void clearAllNode();


    void help(int type,const QString &addr, const QString &paddr,
              ushort _name,bool status);

    void addNode(int type,const QString &addr, const QString &paddr,
                 ushort _name,bool status);

    void removeSameEage(QList<Edge *> &l1,QList<Edge *> &l2);


    QPoint get_pos(ZigBeeNode *node);


    int get_level(const QString &paddr);
    int get_index(const QString &paddr);


};

#endif // ZBNNMW_H
